cmake_minimum_required(VERSION 3.15)

project(otl)

set(CMAKE_CXX_STANDARD 17)

option(USE_HW_CODEC "use hardware accelerator" ON)

add_compile_options(-fPIC)

set(UTILITY_TOP ${CMAKE_CURRENT_SOURCE_DIR})

# Shared find modules path
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/common/cmake")

# Use Rivs find modules (RIVS_ROOT defaults to /opt/rivs, can be overridden)
# Prefer Rivs if available; fall back to system FFmpeg inside FindRivsFFmpeg.cmake
find_package(Rivs QUIET)
find_package(RivsFFmpeg REQUIRED)
find_package(Threads REQUIRED)


include_directories(${UTILITY_TOP} ${RivsFFmpeg_INCLUDE_DIRS})

if (USE_HW_CODEC)
    set(DECODE_SRC stream_decode_hw.cpp)
else()
    set(DECODE_SRC stream_decode.cpp)
endif()

add_library(otl
        otl_arch.cpp
        stream_sei.cpp
        otl_baseclass.cpp
        stream_demuxer.cpp
        otl_timer.cpp
        otl_string.cpp
        optimized_timer.cpp
        stream_encoder.cpp
        otl_log.cpp
        ${DECODE_SRC}
        )

add_executable(timer_performance_test timer_performance_test.cpp)
target_link_libraries(timer_performance_test otl
	Rivs::FFMPEG
	        pthread
)

add_executable(timestamp_test timestamp_test.cpp)
target_link_libraries(timestamp_test otl
	Rivs::FFMPEG
		pthread)

add_executable(log_test test_log.cpp)
target_link_libraries(log_test otl
        Rivs::FFMPEG
        pthread)

add_executable(log_telnet_test test_telnet.cpp)
target_link_libraries(log_telnet_test otl
        Rivs::FFMPEG
        pthread)

add_executable(test_thread_queue test_thread_queue.cpp)
target_link_libraries(test_thread_queue otl
        Rivs::FFMPEG
        pthread)

add_executable(test_stream_pusher test_stream_pusher.cpp)
target_link_libraries(test_stream_pusher otl
	        Rivs::FFMPEG
	        pthread)
